

import java.io.IOException;
import java.util.List;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import sessionbeans.RegistrationBeanRemote;

/**
 * Servlet implementation class GetAbilitiesServlet
 */
public class GetAbilitiesServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetAbilitiesServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		List<String> abilities;
		InitialContext context;
		
		try {
			context = new InitialContext();
			Object ref = context.lookup("RegistrationBeanRemote");
			RegistrationBeanRemote registrationBean = (RegistrationBeanRemote)PortableRemoteObject.narrow(ref, RegistrationBeanRemote.class);
			abilities = registrationBean.getAbilityList();
			HttpSession session = request.getSession();
			session.setAttribute("abilities",abilities);
			if(request.getParameter("unregistered") != null){
				response.sendRedirect("UnregisteredSearchPage.jsp");
				return;
			}
			response.sendRedirect((String)request.getSession().getAttribute("redirected"));
		} catch (NamingException e) {
			response.getWriter().println("Naming Exception!");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
